<?php

namespace app\controller\admin\cnf;

use app\bll\UserGrade as BllUserGrade;
use core\controller\AdminBase;
use Exception;
use support\View;

class UserGrade extends AdminBase
{
    public function index()
    {
        $bllUserGrade = new BllUserGrade();
        $grades       = $bllUserGrade->select();
        View::assign('grades', $grades);
        return $this->view();
    }

    public function add()
    {
        if (is_post()) {
            try {
                $bllUserGrade = new BllUserGrade();
                $bllUserGrade->add(request()->post());
            } catch (Exception $ex) {
                return $this->error($ex->getMessage());
            }
            return $this->success();
        } else {
            return $this->view();
        }
    }


    public function edit()
    {
        $id           = request()->get('id');
        $bllUserGrade = new BllUserGrade();
        if (is_post()) {

            try {
                $bllUserGrade ->edit($id,request()->post());
            } catch (Exception $ex) {
                return $this->error($ex->getMessage());
            }
            return $this->success();
        } else {
            $gradeinfo = $bllUserGrade->find($id);
            View::assign('gradeinfo', $gradeinfo);
            return $this->view();
        }
    }


    public function delete()
    {

        try {
            $id           = request()->get('id');
            $bllUserGrade = new BllUserGrade();
            $bllUserGrade->delete($id);
        } catch (Exception $ex) {

            return $this->error($ex->getMessage());
        }
        return $this->success();
    }
}
